<template>
	<view class="goods-show">
		<view class="goods-show-header" @click="goodsClick(goods)">
			<view>
				<image :src="imageSrc(goods.multimediaUrl)" mode="aspectFill" class="goods-image">
				</image>
			</view>
		</view>
		<view class="goods-show-body">
			<view class="goods-intro">
				<view class="goods-name">{{goods.name}}</view>
				<view class="goods-price">{{priceTransform(goods.price)}}/{{goods.specification || ''}}
				<text class="goods-hua-price" v-if="goods.topPrice">
					{{priceTransform(goods.topPrice)}}/{{goods.specification || ''}}
				</text>
				</view>
				
			</view>
			<view class="goods-tag">
				<uni-tag :text="`${goods.minSaleNum}${goods.specification || ''}起售`" v-if="goods.minSaleNum > 1"
					class="goods-tag-item"  size="small"/>
				<uni-tag :text="storeText(goods.stock)" class="goods-tag-item" size="small"></uni-tag>
				<uni-tag :text="`限购${goods.limitNum}${goods.specification || ''}`" class="goods-tag-item"
					v-if="goods.limitNum" size="small"></uni-tag>
				<uni-tag :text="`限购${goods.limitTimes}次`" class="goods-tag-item" v-if="goods.limitTimes"
					size="small"></uni-tag>
			</view>
			<!-- <view class="goods-tag"><uni-tag :text="storeText(goods.store)"></uni-tag></view> -->
			<view class="goods-number-area">
				<my-number-box v-model="goods.count" background="#1aad19" color="#fff" :max="maxValue(goods)"
					:disabled="(goods.limitNum || goods.stock) <= 0" @plus.stop="plus(goods)" @minus="minus(goods)" />
			</view>
		</view>
		<!-- <view class="goods-show-footer">
			<my-number-box v-model="goods.count"  background="#1aad19" color="#fff"  :max="goods.store" :disabled="goods.store <= 0"
				@change.stop="numberChange(goods)"/>
		</view> -->
	</view>
</template>

<script>
	import {
		transform
	} from '@/minix/mixin.js'
	export default {
		mixins: [transform],
		name: "goods-sale-item",
		props: {
			goods: {
				type: Object,
				require: true,
			}
		},
		data() {
			return {

			};
		},
		methods: {
			maxValue(goods) {
				if (goods.stock <= 0) {
					return 0;
				}

				if (goods.limitNum) {
					return goods.limitNum > goods.stock ? goods.stock : goods.limitNum
				}
				return goods.stock
			},
			goodsClick(item) {
				this.$emit("goodsClick", item)
			},
			numberChange(item) {
				this.$emit("numberChange", item)
			},
			plus(item) {
				this.$emit('plus', item)
			},
			minus(item) {
				this.$emit('minus', item)
			},
			storeText(stock) {
				stock = stock || 0
				if (stock <= 0) {
					return '已售罄'
				} else if (stock >= 500) {
					return ""
				} else {
					return '剩余' + stock
				}
			},
			storeType(stock) {
				stock = stock || 0
				return stock <= 0 ? "error" : "warning"
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goods-show {
		background-color: #fff;
		padding-top: 10px;
		display: flex;
		flex-direction: row;
		padding: 5px;
		border-bottom: 1px solid #ded8d8;

		.goods-show-header {
			display: flex;
			flex-direction: row;

			.goods-intro {
				display: flex;
				flex-direction: column;
				margin-left: 10px;
				padding: 0;

				.goods-name {
					font-size: 16px;
					font-weight: normal;
				}

				.goods-hua-price {
					text-decoration-line: line-through;
					color: #afaeae;
					font-size: 14px;
				}

				.goods-price {
					font-size: 18px;
					color: #ea6d31;
					font-weight: bold;
				}
			}

		}

		.goods-tag {
			margin-top: 0;
		}


		.goods-image {
			width: 100px;
			height: 100px;
			border-radius: 5px;
		}

		.goods-show-body {
			margin-left: 5px;
			display: flex;
			flex-direction: column;
			justify-content: flex-start;
			align-items: flex-start;
			flex: 1;
			.goods-intro{
				padding-top: 0;
			}

		}

		.goods-show-footer {
			display: flex;
			justify-content: flex-end;
			flex-direction: column;
		}
	}

	.goods-tag-item {
		margin-left: 5px;
		margin-top: 5px;
		display: inline-flex;
	}

	.goods-number-area {
		margin-top: 5px;
		margin-right: 10px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
	}
</style>